package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.AirCity;
import cn.wolfcode.luowowo.article.mapper.AirCityMapper;
import cn.wolfcode.luowowo.article.mapper.AirTicketOrderMapper;
import cn.wolfcode.luowowo.article.service.IAirCityService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class AirCityServiceImpl implements IAirCityService{
    @Autowired
    private AirCityMapper cityMapper;

    @Autowired
    private AirTicketOrderMapper airTicketOrderMapper;


    @Override
    public List<AirCity> getStartSiteByIshot(String[] arr) {
        List<AirCity> airCities = cityMapper.selectStartSiteByIshot();
        // 定义一个容器
        List<String> cities = new ArrayList<>();
        // 遍历城市,把城市放到容器中, 如果容器中存在该城市, 则移除
        for(int i = 0; i < airCities.size(); i++){
            if (cities.contains(airCities.get(i).getName())){
                airCities.remove(i);
                i--;
            }
            cities.add(airCities.get(i).getName());
        }

        // 拼音首字母对应的城市
        if (arr != null && arr.length > 0){
            List<AirCity> airTicketsCities = new ArrayList<>();
            for(int i = 0; i < airCities.size(); i++){
                String pinyin = airCities.get(i).getPinyin();
                for (String letter : arr) {
                    if (pinyin.equalsIgnoreCase(letter)){
                        airTicketsCities.add(airCities.get(i));
                    }
                }
            }
            return airTicketsCities;
        }

        return airCities;
    }


}
